/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.servelet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Bach
 */
public class Navigation extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            int option = Integer.parseInt(request.getParameter("menu"));
            int id = 0;
            try {
                id = Integer.parseInt(request.getParameter("id"));
            } catch (Exception e) {
            }

            switch (option) {
                case 1:
                    process(request, response, option, id);
                    break;
                case 2:
                    process(request, response, option, id);
                    break;
                case 6:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("accAdmin.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 7:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("update_AccAdmin.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 8:
                    process(request, response, option, id);
                    break;
                case 9:
                    process(request, response, option, id);
                    break;
                case 10:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("view_feedback.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 11:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("view_feedback.jsp?menu=" + option + "&id=" + id + "&save=1").forward(request, response);
                    break;
                case 12:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("countries.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 13:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("caste.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 139:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("caste.jsp?menu=13&id=" + id + "&create=1").forward(request, response);
                    break;
                case 14:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("professional.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 149:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("professional.jsp?menu=" + option + "&id=" + id+"&create=1").forward(request, response);
                    break;
                case 15:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("religion.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 16:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("preferences.jsp?menu=" + option + "&id=" + id).forward(request, response);
                    break;
                case 17:
                    request.setAttribute("option", "ok");
                    request.getRequestDispatcher("admin_payments.jsp?menu=" + option + "&gtid=" + id).forward(request, response);
                    break;
                default:
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
    }

    private void process(HttpServletRequest request, HttpServletResponse response, int option, int id) {
        try {
            request.setAttribute("option", "ok");
            request.setAttribute("id", id);
            request.getRequestDispatcher("manager.jsp?menu=" + option).forward(request, response);
        } catch (ServletException ex) {
            Logger.getLogger(Navigation.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Navigation.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
//  if (option == 6) {
//                request.setAttribute("option", "ok");
//                request.getRequestDispatcher("accAdmin.jsp?menu=" + option).forward(request, response);
//            } else if (option == 7) {
//                int id = Integer.parseInt(request.getParameter("id"));
//                request.setAttribute("option", "ok");
//                request.getRequestDispatcher("update_AccAdmin.jsp?menu=" + option+"&id="+id).forward(request, response);
//            } else {

